class AcGamePlayground {
    constructor(root, before_menu) {
        this.root = root;
        this.before_menu = before_menu;
        this.className = "playground";
        this.$playground = $(`<div class="ac-game-playground"></div>`);

        this.hide();
        this.root.$ac_game.append(this.$playground);
        this.width = this.$playground.width();
        this.height = this.$playground.height();
        this.game_map = new GameMap(this);
        this.height *= 0.95
        this.players = [];
        let player_radius = this.height * 0.05;
        let player_x = Math.random() * this.width;
        let player_y = Math.random() * this.height;
        if(player_x < player_radius) player_x = player_radius;
        if(player_x + player_radius > this.width) player_x = this.width - player_radius;
        if(player_y < player_radius) player_y = player_radius;
        if(player_y + player_radius > this.height) player_y = this.height - player_radius;
        this.players.push(new Player(this, player_x, player_y, this.height * 0.05, "white", this.height * 0.3, true));

        for (let i = 0; i < 5; i ++ ) {
            this.players.push(new Player(this, Math.random() * this.width + this.height * 0.15, Math.random() * this.height + this.height * 0.15, this.height * 0.05, this.get_random_color(), this.height * 0.3, false));
        }

        this.start();
    }

    get_random_color() {
        let colors = ["purple", "pink", "grey", "green", "yellow", "cyan"];
        return colors[Math.floor(Math.random() * colors.length)];
    }

    start() {
    }

    show() {  // 打开playground界面
        this.$playground.show();
    }

    hide() {  // 关闭playground界面
        this.$playground.hide();
    }
}
